package com.gt.web.srv.interceptors;


import com.alibaba.ttl.TransmittableThreadLocal;
import com.gt.web.srv.web.api.resource.ResponseUserVo;
import com.gt.web.srv.web.api.resource.dto.TokenDto;

/**
 * token 用户信息透传
 *
 * @author Yu Chaohua
 * @date 2024/5/23 0:11
 */
public class AuthUserContext {

    private static final ThreadLocal<TokenDto> USER_INFO_IN_TOKEN_HOLDER = new TransmittableThreadLocal<>();

    public static TokenDto get() {
        return USER_INFO_IN_TOKEN_HOLDER.get();
    }

    public static void set(TokenDto userInfoInTokenBo) {
        USER_INFO_IN_TOKEN_HOLDER.set(userInfoInTokenBo);
    }

    public static void clean() {
        if (USER_INFO_IN_TOKEN_HOLDER.get() != null) {
            USER_INFO_IN_TOKEN_HOLDER.remove();
        }
    }

}
